package org.dromara.easytl.parser;

/**
 * Token 表示词法分析的最小单元
 *
 * @author EasyTL Team
 */
public class Token {

    private final int type;
    private final String value;
    private final int line;
    private final int column;
    private final int position;

    public Token(int type, String value, int line, int column, int position) {
        this.type = type;
        this.value = value;
        this.line = line;
        this.column = column;
        this.position = position;
    }

    public Token(int type, int line, int column, int position) {
        this(type, null, line, column, position);
    }

    public int getType() {
        return type;
    }

    public String getValue() {
        return value;
    }

    public int getLine() {
        return line;
    }

    public int getColumn() {
        return column;
    }

    public int getPosition() {
        return position;
    }

    @Override
    public String toString() {
        if (value != null) {
            return String.format("Token{type=%s, value='%s', line=%d, column=%d}",
                    TokenType.getName(type), value, line, column);
        } else {
            return String.format("Token{type=%s, line=%d, column=%d}",
                    TokenType.getName(type), line, column);
        }
    }
}

